<%@page import="com.award.model.Commodity"%>
<%@page import="com.award.jdbc.dao.JdbcDao"%>
<%@page import="com.award.model.Relationship"%>
<%@page import="com.award.model.User"%>
<%@ page language="java" import="java.util.*"
	contentType="text/html; charset=utf-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
	User user = null;
	if (null != session.getAttribute("user")) {
		user = (User) session.getAttribute("user");
	}
	JdbcDao jd=new JdbcDao();
	List<Relationship> re_list=jd.queryOnesRelationship(user.getId());
	List<Commodity> doing_list=new ArrayList<Commodity>();
	List<Commodity> done_list=new ArrayList<Commodity>();
	Commodity cd=null;
	for(Relationship re:re_list){
	cd=jd.queryCommodityByID(re.getCommodityID());
	if(0==cd.getAward()){
	doing_list.add(cd);
	}else if(1==cd.getAward()&&1==re.getChecked())
	done_list.add(cd);
	}
%>

<!DOCTYPE html>
<html>
<head>
<base href="<%=basePath%>">

<title>My JSP 'account.jsp' starting page</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="./css/vendor/bootstrap/css/bootstrap.min.css"
	rel="stylesheet">
<link href="./css/flat-ui.min.css" rel="stylesheet">
<link href="./css/style.min.css" rel="stylesheet">
<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->

</head>

<body>
	<jsp:include page="./border/header.jsp" flush="true"></jsp:include>
	<div id="account" class="container">
		<section class="account-info" width="100%">
		<div class="user-img" >
			<img src="<%=user.getUserImgURL()%>">
		</div>
		<br/>
		<div  class="user-info">
			<span class="user-name ng-binding">昵称：<%=user.getUsername()%></span><br>
			<%
				if (null != user.getAddress()) {
			%>
			<span class="user-name ng-binding">收件地址：<%=user.getAddress()%></span><br>
			<%
				} else {
			%>
			<span class="user-name ng-binding">请填写收货地址*</span><br>
			<%
				}
			%>
			<span class="user-name ng-binding">取货电话：<%=user.getTelephone()%></span><br>
		</div>
		</section>
		<div class="title-page">
			<h1>个人记录</h1>
		</div>
		<div>
			<!-- Nav tabs -->
			<ul class="nav nav-tabs" role="tablist">
				<li role="presentation" class="active"><a href="#tab1"
					aria-controls="tab1" role="tab" data-toggle="tab">正在进行</a></li>
				<li role="presentation"><a href="#tab2" aria-controls="tab2"
					role="tab" data-toggle="tab">获得的奖品</a></li>
			</ul>

			<!-- Tab panes -->
			<div class="tab-content" width="100%">
				<div role="tabpanel" class="tab-pane active" id="tab1">
					<table width="100%">
					<% for(Commodity c:doing_list){ %>
					<tr>
					<td><%= c.getCommodityName()%></td>
					<td><%= c.getPrice() %></td>
					<td><%= c.getSelectPeopleNum() %>/<%= c.getTotal() %></td>
					<td><a href="./jsp/raffle.jsp?CommodityID=<%= c.getId() %>">Go！！！</a></td>
					</tr>
					<%} %>
					</table>
				</div>
				<div role="tabpanel" class="tab-pane" id="tab2">
					<table width="100%">
					<% for(Commodity c:done_list){ %>
					<tr>
					<td><%= c.getCommodityName()%></td>
					<td><%= c.getPrice() %></td>
					<td>恭喜您获得该商品</td>
					<td><a href="./jsp/raffle.jsp?CommodityID=<%= c.getId() %>">Go！！！</a></td>
					</tr>
					<%} %>
				</table>
				</div>
			</div>
		</div>
	</div>
	<footer id="footer">
	<div>Copyright &copy; 2017</div>
	</footer>

	<script src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
	<script src="./js/flat-ui.min.js"></script>
	<script src="./js/script.js"></script>
</body>
</html>
